package org.example.comp_algorithm_back;

import com.alibaba.fastjson.JSON;
import org.example.comp_algorithm_back.domain.CompWord;
import org.example.comp_algorithm_back.vo.WordSearchVo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.*;
import java.util.stream.Collectors;

@SpringBootTest
public class SurveyDataGenerator {
    private static final List<String> highScoreKeywords = Arrays.asList("道法", "青云志", "梦幻西游");
    private static  List<CompWord>  keywords;
    private static final Random random = new Random();
    private static final int rows = 20;
    private static final int cols;


    static {
        String js = "{\"seedWord\":\"诛仙\",\"keywords\":[{\"midWord\":\"道法\",\"word\":\"路线\",\"comp\":2.0},{\"midWord\":\"天音\",\"word\":\"天一\",\"comp\":1.14286},{\"midWord\":\"周一\",\"word\":\"英语\",\"comp\":0.85714},{\"midWord\":\"称号\",\"word\":\"dnf\",\"comp\":0.29412},{\"midWord\":\"青云\",\"word\":\"百度云\",\"comp\":0.23264},{\"midWord\":\"手游\",\"word\":\"梦幻西游\",\"comp\":0.22489},{\"midWord\":\"青云志\",\"word\":\"百度云\",\"comp\":0.17803},{\"midWord\":\"任务\",\"word\":\"剑灵\",\"comp\":0.17431},{\"midWord\":\"宠物\",\"word\":\"洛克\",\"comp\":0.056},{\"midWord\":\"技能\",\"word\":\"洛克\",\"comp\":0.03302},{\"midWord\":\"职业\",\"word\":\"技术\",\"comp\":0.0268},{\"midWord\":\"厉害\",\"word\":\"英雄\",\"comp\":0.02381},{\"midWord\":\"梦幻\",\"word\":\"手游\",\"comp\":0.01645},{\"midWord\":\"攻略\",\"word\":\"密室\",\"comp\":0.01264},{\"midWord\":\"小说\",\"word\":\"倾城\",\"comp\":0.00776},{\"midWord\":\"时间\",\"word\":\"杭州\",\"comp\":0.0043},{\"midWord\":\"全集\",\"word\":\"txt\",\"comp\":0.00335},{\"midWord\":\"官网\",\"word\":\"手机\",\"comp\":0.00312},{\"midWord\":\"txt\",\"word\":\"全集\",\"comp\":0.00283},{\"midWord\":\"手机\",\"word\":\"游戏\",\"comp\":0.00153}],\"wordMsg\":\"\",\"wordCount\":20,\"flag\":false,\"means\":[],\"stdDevs\":[],\"diff\":[],\"rankedKeywords\":null,\"time\":4065,\"strong\":[],\"weak\":[]}";
        WordSearchVo vo = JSON.parseObject(js, WordSearchVo.class);
        keywords = vo.getKeywords();
        cols = vo.getWordCount();
    }

    @Test
    public void test() {
        for (int i = 0; i < rows; i++) {
            List<Integer> rowScores = generateRowScores();
            printRow(rowScores);
        }
    }

    private static List<Integer> generateRowScores() {
        List<Integer> scores = new ArrayList<>();
        for (CompWord keyword : keywords) {
            if (highScoreKeywords.contains(keyword.getMidWord()) || highScoreKeywords.contains(keyword.getWord())) {
                scores.add(generateHighScore());
            } else {
                scores.add(generateRandomScore());
            }
        }
        // 添加随机填充以确保每行有20个评分
        while (scores.size() < cols) {
            scores.add(generateRandomScore());
        }
        return scores;
    }

    private static int generateHighScore() {
        // 高分关键词的评分范围偏向高分，但允许一些变化
        return 4 + random.nextInt(2); // 产生4或5
    }

    private static int generateRandomScore() {
        // 其他关键词的评分范围更广
        return 1 + random.nextInt(5); // 产生1到5之间的随机数
    }

    private static void printRow(List<Integer> rowScores) {
        String line = rowScores.stream()
                .map(String::valueOf)
                .collect(Collectors.joining(" "));
        System.out.println(line);
    }

}
